#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;
typedef pair<int, int> PII;

void merge(vector<PII> &segs)
{
    vector<PII> ret;
    sort(segs.begin(), segs.end());
    int st = INT_MIN, ed = INT_MIN;
    for (auto seg : segs)
    {
        if (ed < seg.first)
        {
            if (st != INT_MIN)
            {
                ret.push_back({st, ed});
            }
            st = seg.first;
            ed = seg.second;
        }
        else
        {
            ed = max(ed, seg.second);
        }
    }

    if (st != INT_MIN)
    {
        ret.push_back({st, ed});
    }
    segs = ret;
}

int main()
{
    vector<PII> segs;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        scanf("%d %d", &l, &r);
        segs.push_back({l, r});
    }

    merge(segs);

    printf("%d", segs.size());
    return 0;
}